<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <jsp:include page="../common/header.jsp" />
    <script type="text/javascript">
        function save() {
            $save = $("input[name=save]");
            $save.bind("click", function () {
                if ($.trim($("#bianHao").val()) == "") {
                    $("#bianHao").css({border: "solid 2px #f00"});
                } else if ($.trim($("#name").val()) == "") {
                    $("#bianHao").css({border: ""});
                    $("#nameError").text("课程名称必填");
                } else if ($.trim($("#score").val()) == "") {
                    $("#bianHao").css({border: ""});
                    $("#nameError").text("");
                    $("#scoreError").text("考试总分必填");
                } else {
                    $("#form1").submit();
                }

            });
        }
        function autoExec() {
            var $autoExec = $("input.autoExec");
            $autoExec.bind("click", function () {
                $.ajax(
                        {
                            type: "post",
                            url: "autoExecCourseBh.action",
                            dataType: "json",
                            success: function (data) {
                                var d = eval("(" + data + ")");
                                $("#bianHao").attr("value", "" + d.bianHao + "");
                            },
                            error: function () {
                                alert("系统异常，请稍后重试！");
                            }
                        }
                );
            });
        }
        $(function () {
            save();
            /* $(".button").button(); */
            $("#selectDeleteBtn").button();
            autoExec(); //自动激活课程编号
            $("#dialog").dialog({
                autoOpen: false,
                width: 400,
                buttons: [{
                    text: "关闭",
                    click: function () {
                        $(this).dialog("close");
                    }
                }]
            });

            // Link to open the dialog
            $("#dialog-link").click(function (event) {
                $("#dialog").dialog("open");
                event.preventDefault();
            });

            // Hover states on the static widgets
            $("#dialog-link").hover(function () {
                $(this).addClass("ui-state-hover");
            }, function () {
                $(this).removeClass("ui-state-hover");
            });

        });
    </script>
    <jsp:include page="../common/mycss.jsp" />
</head>
<body>
<div class="lyear-layout-web">
    <div class="lyear-layout-container">
        <!--左侧导航-->
        <aside class="lyear-layout-sidebar">
            <!-- logo -->
            <div id="logo" class="sidebar-header">
                <jsp:include page="../common/title.jsp" />
            </div>
            <div class="lyear-layout-sidebar-scroll">
                <jsp:include page="../common/menu.jsp" />
            </div>
        </aside>
        <!--End 左侧导航-->
        <jsp:include page="../common/top.jsp" />
        <!--页面主要内容-->
        <main class="lyear-layout-content">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-lg-12">
                        <div class="card">
                            <div class="card-toolbar clearfix">
                                <h5>课程管理&nbsp;&gt;&nbsp;课程信息添加&nbsp;&nbsp;
                                    <span style="color:#000;">(目前已有<s:property
                                            value="count"/>条课程信息)
			</span>
                                </h5>
                            </div>
                            <div class="card-body">
                                <div id="accordion">

                                    <div class="frame">
                                        目前存在如下课程:
                                        <br>
                                        <br>
                                        <table class="datalist">
                                            <s:iterator value="courses" status="st">
                                                <s:if test="#st.index % 15 == 0">
                                                    <tr>
                                                </s:if>
                                                <td>
                                                    <div><a href="#"><s:property value="name"/></a></div>
                                                    <br/>
                                                    <div style="text-align: center"><s:property value="score"/></div>
                                                </td>
                                                <s:if test="#st.index % 15 == 14">
                                                   </tr>
                                                </s:if>
                                            </s:iterator>
                                        </table>
                                        <br>
                                        <br>
                                        <a href="#" id="dialog-link" class="ui-state-default ui-corner-all"><button id="selectDeleteBtn">选择删除</button></a> <br/>
                                        <p style="color:red">(说明：只能删除没有关联教师的课程信息)</p>
                                        <br/>
                                        <hr/>
                                        <form id="form1" name="form1" method="post" action="courseFormRegister.action">
                                            <table class="datalist">
                                                <tr>
                                                    <th align="right"><strong>课程编号</strong></th>
                                                    <td><input type="text"
                                                               name="course.bianHao" id="bianHao" readonly="readonly"/> <input type="button"
                                                                                                                               name="autoExec"
                                                                                                                               id="autoExec"
                                                                                                                               class="autoExec"
                                                                                                                               value="自动激活"/></td>
                                                </tr>
                                                <tr>
                                                    <th align="right"><strong>课程名称</strong></th>
                                                    <td><input type="text"
                                                               name="course.name" id="name"/><span id="nameError" class="ErrorStyle"></span></td>
                                                </tr>
                                                <tr>
                                                    <th align="right"><strong>考试总分</strong></th>
                                                    <td><input type="number"
                                                               name="course.score" id="score"/><span id="scoreError" class="ErrorStyle"></span></td>
                                                </tr>
                                                <tr>
                                                    <td colspan="2" align="center"><input type="button"
                                                                                          name="save" id="save" value="保存"/> <input type="reset"
                                                                                                                                    name="button"
                                                                                                                                    id="button"
                                                                                                                                    value="取消"/></td>
                                                </tr>
                                            </table>
                                        </form>

                                    </div>
                                </div>
                                <div id="dialog" title="选择删除">
                                    <form id="form2" name="form2" method="post" action="courseDelete.action">
                                        <s:iterator value="coursesEnableDeL">
                                            <input type="checkbox" name="courseDel"
                                                   value='<s:property value="bianHao" />'/>课程编号：<s:property
                                                value="bianHao"/>&nbsp;&nbsp;课程名称：<s:property value="name"/>
                                            <br/>
                                            <hr/>
                                        </s:iterator>
                                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" value="删除"/>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>

                </div>

            </div>

        </main>
        <!--End 页面主要内容-->
    </div>
</div>
</body>
</html>
